// mircoApp/video_popularize_award/index/index.js
var app = getApp();
const skinBehavior = require('../../../utils/themeSkin/skinBehavior');
var int = (app.globalData.statusBarHeight * 2) + 20;
Page({

  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    no_buy: app.data.host + '/static/local/video-promotion-rewards/no-buy.png',
    member_info: {},
    list: [],
    page: 1,
    total_page: 1,
    statusBarHeight: int,
    globalData: {
      navHeight: 0,
      navTop: 0,
      jnheight: 0,
      jnwidth: 0,
    },
    language: "",
    title_text:"",
  },
  goto(e) {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/mircoApp/video_popularize_award/detail/detail?id='+item.id,
    })
  },
  back() {
    wx.navigateBack();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.initNavBar();
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
    });
    this.getData();
  },
  getData(page = 1) {
    app._postNetWork({
      url: app.getNetAddresss("plugin.video-promotion-rewards.frontend.income.getInfo"),
      data: {
        page
      },
      success: resdata => {
        let {
          result,
          data,
          msg,basic_info={}
        } = resdata.data;
        if (result) {
          let title_text = basic_info?.plugin_setting?.video_promotion_rewards?.plugin_name;
          let list = page == 1 ? data.list.data : this.data.list.concat(data.list.data);
          if(this.data.title_text==''){
            this.setData({title_text});
          }
          this.setData({
            list,
            member_info: data.member_info
          })
          this.data.page = data.list.current_page;
          this.data.total_page = data.list.last_page;
        } else {
          app.tips(msg);
        }
      }
    })
    
  },
  initNavBar() {
    //获取菜单按钮的布局位置信息
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    console.log(menuButtonObject);
    //获取系统信息
    wx.getSystemInfo({
      success: res => {
        //状态栏的高度
        let statusBarHeight = res.statusBarHeight,
          //胶囊按钮与顶部的距离
          navTop = menuButtonObject.top,
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2;
        let globalData = {};
        globalData.navHeight = navHeight; //导航栏高度
        globalData.navTop = navTop; //胶囊按钮与顶部的距离
        globalData.jnheight = menuButtonObject.height; //胶囊的高度
        globalData.jnwidth = menuButtonObject.width; //胶囊的宽度
        this.setData({
          globalData
        })
      },
      fail(err) {
        console.log(err);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(this.data.page>=this.data.total_page) return;
    let page =  this.data.page + 1;
    this.getData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})